package com.tms.project.tms.score.service.impl;

import java.util.List;

import com.tms.common.utils.DateUtils;
import com.tms.project.tms.score.domain.ScoreDetailVO;
import com.tms.project.tms.score.domain.ScoreVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tms.project.tms.score.mapper.ScoreMapper;
import com.tms.project.tms.score.domain.Score;
import com.tms.project.tms.score.service.IScoreService;
import com.tms.common.utils.text.Convert;

/**
 * tmsService业务层处理
 *
 * @author xyl
 * @date 2021-03-24
 */
@Service
public class ScoreServiceImpl implements IScoreService {
    @Autowired
    private ScoreMapper scoreMapper;

    /**
     * 查询tms
     *
     * @param scoreId tmsID
     * @return tms
     */
    @Override
    public Score selectScoreById(Long scoreId) {
        return scoreMapper.selectScoreById(scoreId);
    }

    /**
     * 查询tms列表
     *
     * @param score tms
     * @return tms
     */
    @Override
    public List<Score> selectScoreList(Score score) {
        return scoreMapper.selectScoreList(score);
    }

    /**
     * 新增tms
     *
     * @param score tms
     * @return 结果
     */
    @Override
    public int insertScore(Score score) {
        score.setCreateTime(DateUtils.getNowDate());
        return scoreMapper.insertScore(score);
    }

    /**
     * 修改tms
     *
     * @param score tms
     * @return 结果
     */
    @Override
    public int updateScore(Score score) {
        score.setUpdateTime(DateUtils.getNowDate());
        return scoreMapper.updateScore(score);
    }

    /**
     * 删除tms对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteScoreByIds(String ids) {
        return scoreMapper.deleteScoreByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除tms信息
     *
     * @param scoreId tmsID
     * @return 结果
     */
    @Override
    public int deleteScoreById(Long scoreId) {
        return scoreMapper.deleteScoreById(scoreId);
    }

    @Override
    public List<Score> selectScoreRepeat(Score score) {
        Score temp = new Score();
        if(score.getType() == 1){
            temp.setIpAddress(score.getIpAddress());
            temp.setTeacherId(score.getTeacherId());
        }else if(score.getType() == 2){
            temp.setCreateBy(score.getCreateBy());
            temp.setTeacherId(score.getTeacherId());
        }else{
            return null;
        }
        return scoreMapper.selectScoreList(temp);
    }

    @Override
    public List<ScoreVO> selectScoreVOList(Score score) {
        return scoreMapper.selectScoreVOList(score);
    }

    @Override
    public List<ScoreDetailVO> selectScoreDetailVoList(int type, Integer teacherRecordId) {
        return scoreMapper.selectScoreDetailVoList(type,teacherRecordId);
    }
}
